home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
aztcmtsk.arc
/
AZTASK.TSH
< prev
Wrap
Text File
|
1986-03-24
|
5KB
|
113 lines
/* ========================================================== */
/* */
/* TASKING.H -- interface file for Tasking, Queues */
/* */
/* The Task, Queue, and Event structures are defined here in */
/* terms of anonymous words. This "opaque" definition of the */
/* structures allows the client program to declare pointers */
/* to them, but not to interpret their internal values. Full */
/* definitions of them appear in TASKING.C. See also TROOT.C, */
/* the version of CROOT modified for tasking. */
/* */
/* Also defined here are externs for the functions that work */
/* on these structures, with declarations of their arguments */
/* for use by compilers that check argument types. */
/* */
/* Note that any function that takes a Queue will take an */
/* Event instead, and that an Event is merely a one-item */
/* Queue. Thus posting an Event is merely putting one item */
/* in the event's queue, and waiting on an Event is getting */
/* from its queue. */
/* */
/* Copyright (C) 1986 by David E. Cortesi, 415 Cambridge Ave */
/* Suite 18, Palo Alto, CA 94306. Permission to copy and */
/* redistribute without charge is granted provided only that */
/* this notice is retained. Distribution for a fee, whether */
/* alone or as part of another product and whether or not for */
/* profit, requires explicit permission from the author. */
/* ========================================================= */
struct Queue { unsigned qwords[5]; };
struct Event { unsigned ewords[7]; };
struct Task { unsigned twords[5]; };
/* creates a queue that can hold num words, num at least 1. */
extern struct Queue *qmake(/*num*/) /*int num*/;
/* creates an Event (but not a social one) */
extern struct Event *evmake();
/* returns oldest item from *adq, waiting if necessary */
extern unsigned qget(/*adq*/) /*struct Queue *adq*/;
/* installs val as newest item in *adq, waits if *adq is full */
extern int /* void */ qput(/*adq,val*/)
/*struct Queue *adq; unsigned val*/;
/* returns 1 if *adq is empty, i.e. if qget(adq) would wait */
extern int qempty(/*adq*/) /*struct Queue *adq*/;
/* returns 1 if *adq is not empty (qget(adq) would not wait) */
extern int qnotmt(/*adq*/) /*struct Queue *adq */;
/* returns 1 if *adq is full, i.e. if qput(adq) would wait */
extern int qfullQ(/*adq*/) /*struct Queue *adq*/;
/* returns 1 if *adq is not full (qput(adq) wouldn't wait */
extern int qnotfull(/*adq*/) /*struct Queue *adq*/;
#define evwait(E) qget((E))
#define evpost(E) qput((E),1)
#define posted(E) qnotmt((E))
/* creates a task to execute in fun() with a stack of nst words.
function fun takes nar arguments, which should follow, for
example, after t = maketask(&doit,256,2,"first",myevent), the
new task would with a call to doit("first",myevent) */
extern struct Task *maketask(/*fun,nst,nar[,others...]*/)
/*int (*fun)(), nst, nar*/;
/* returns the active tasks Task address (for passing to other
functions so they can sleep you) */
extern struct Task *myTask();
/* ends the active task (when the last task ends, the program
ends, and not until) */
extern int /*void*/ endtask();
/* kills the specified task. */
extern int /*void*/ killtask(/*adt*/) /*struct Task *adt*/;
/* gives every other task a chance to run before control comes
back to the current task. The qget() function does a defer()
automatically, but qput() does not. Either qget() or defer()
must appear in the tightest loop in any task to avoid
starving other tasks of execution time. */
extern int /*void*/ defer();
/* puts a task to sleep, preventing it from getting any CPU
cycles. requires a twake() to awaken it. */
extern int /*void*/ tsleep(/*adt*/) /*struct Task *adt*/;
/* wakes up a task sleeping from tsleep() (also wakes up a
task waiting on a queue, but it will immediately test the
queue and go to sleep again.) */
extern int /*void*/ twaken(/*adt*/) /*struct Task *adt*/;
/* returns 1 if the named task is active, i.e. would execute
on the next defer() call */
extern int tactive(/*adt*/) /*struct Task *adt*/;
/* returns 0 if the named task is active, 1 if it has been
put to sleep by tsleep(), another nonzero if it is waiting
on a qget or qput call. */
extern int tinact(/*adt*/) /*struct Task *adt*/;